
cc.Class({
    extends: cc.Component,

    properties: {
        _orgPos:cc.v2(0,0),
        _mjLayout:null,
        _data:0
    },

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    start () {
        this.node.on(cc.Node.EventType.TOUCH_START,this.touchStart,this);
        this.node.on(cc.Node.EventType.TOUCH_MOVE,this.touchMove,this);
        this.node.on(cc.Node.EventType.TOUCH_END,this.touchEnd,this);
        this.node.on(cc.Node.EventType.TOUCH_CANCEL,this.touchCancel,this);
        this._orgPos = this.node.position;
    },
    upPos(){
        this._orgPos = this.node.position;
    },
    init(data,mjLayout){
        this._data = data;
        this._mjLayout = mjLayout;
    },
    touchStart(e){
        if(game.curGame.getMeSeatId() != game.curGame.curOperator) return;

    },
    touchMove(e){
        if(game.curGame.getMeSeatId() != game.curGame.curOperator) return;
        let pos = e.getLocation();
        let newpos = this.node.parent.convertToNodeSpaceAR(pos);
        this.node.position = newpos;
    },
    touchEnd(e){
        if(game.curGame.getMeSeatId() != game.curGame.curOperator) return;

        let y = this.node.y;
        if( y - this._orgPos.y > 70){
            pomelo.request('ycmj.ycmjHandler.outCard', {card: this._data}, (res)=>{
                if(res.code != -5 ){
                    // this.node.removeFromParent();
                    // // if(this.node.name != 'moCard'){
                    // //     this._mjLayout.node.emit('outCard',{
                    // //         data:this._data,
                    // //         uuid:this.node.uuid
                    // //     }); 
                    // // }
                    // this.node.destroy();
                }
            });
            return;
        }
        this.node.position = this._orgPos;
    },
    touchCancel(e){
        if(game.curGame.getMeSeatId() != game.curGame.curOperator) return;

        this.node.position = this._orgPos;
    },

    // update (dt) {},
});
